<link rel="stylesheet" href="/static/layui/css/layui.theme.css">
<script type="text/html" id="tpl-header">
    <div class="fly-header layui-bg-black">
        <div class="layui-container">
            <!-- <a class="fly-logo" href="/">
                    <img src="../../res/images/logo.png" alt="layui">
                </a> -->
            <ul class="layui-nav fly-nav layui-hide-xs">
                <li class="layui-nav-item">
                    <a href="/" title="博客首页">博客首页</a>
                </li>
                <!-- 权限检测 -->
                {{# if(d.role==1){ }}
                <li class="layui-nav-item">
                    <a href="/profile/admin.html">平台管理</a>
                </li>
                {{# } }}
                <li class="layui-nav-item">
                    <a href="/profile/" title="个人中心">个人中心</a>
                </li>
                <li class="layui-nav-item">
                    <a href="/profile/writing.html"><i class="layui-icon layui-icon-edit"></i>创作</a>
                </li>
            </ul>
    
            <ul class="layui-nav fly-nav-user">
    
                <!-- 登入后的状态 -->
                <li class="layui-nav-item">
                    <a class="fly-nav-avatar" href="javascript:;">
                        <cite class="layui-hide-xs">{{d.name}}</cite>
                        <!-- <i class="iconfont icon-renzheng layui-hide-xs" title="认证信息：layui 作者"></i> -->
                        <!-- <i class="layui-badge fly-badge-vip layui-hide-xs">VIP3</i> -->
                        <img src="{{d.head_image}}">
                    </a>
                    <dl class="layui-nav-child">
                        <!-- <dd><a href="../user/set.html"><i class="layui-icon">&#xe620;</i>基本设置</a></dd> -->
                        <dd><a href="/profile/#/message" style="text-align: center;">我的消息</a></dd>
                        <dd><a href="/u/{{d.username}}" style="text-align: center;">我的主页</a></dd>
                        <dd><a href="/profile/#/about" style="text-align: center;">关于</a> </dd>
                        <hr style="margin: 5px 0;">
                        <dd><a href="javascript:void(0)" id="logout_btn" style="text-align: center;">安全退出</a></dd>
                    </dl>
                </li>
            </ul>
        </div>
    </div>
</script>
<script type="text/javascript">
    app.defTpl('header', function (tplArg) {
        layui.use(['layer', 'laytpl',"element"], function () {
            var laytpl = layui.laytpl, $ = layui.$;
            
            var d={}
            app.base.ajaxGet("/api/personal/getUserInfoCurrent", function (data) {
                data.head_image="/"+ data.head_image

                // 更新用户信息
                var info={}
                info["name"] = data.name;
                info["autograph"] = data.autograph;
                info["head_image"] = data.head_image;
                info["role"] = data.role;
                info["mail"] = data.mail;
                info["username"] = data.username; 
                app.base.setUserInfo(info)

                app.base.tplRender('#tpl-header', data, null, function (html) {
                    $(tplArg.elem).html(html)
                    $("a[href='" + location.pathname + "']").parent().addClass("layui-this")
                    $("#logout_btn").click(function () {
                        
                        app.base.ajaxPost("/api/profile/auth/logout", data.field, function (data) {
                            layer.msg("已经安全退出,正在跳转登录页面")
                            location.href = "/profile/auth.html"
                            app.base.logout()
                        }, function (msg) {
                            layer.msg("安全退出失败 原因：" + msg)
                        })
                        
                    })
                    layui.element.render("nav")
                })
            })

            

            
            




        })
    })

</script>